/*
 * Map.h
 *
 *  Created on: Jan 14, 2013
 *      Author: raysue
 */

#ifndef MAP_H_
#define MAP_H_

#define MAX_NAME_FILE 41

#include <string>
#include <vector>

#include "../../../include/core/GameObject.h"
#include "../../../include/component/Doodle.h"

using namespace eats_core;

class Tile {

	public:

		enum {
			TILE_TYPE_NONE = -1,

			TILE_TYPE_WALKABLE_TRUE,
			TILE_TYPE_WALKABLE_FALSE,
			TILE_TYPE_CONSTRUCTIBLE_TRUE,
			TILE_TYPE_CONSTRUCTIBLE_FALSE
		};

		int     tileID;
		int     walkable;
		int		constructible;

	public:
		Tile(){
			constructible = TILE_TYPE_CONSTRUCTIBLE_TRUE;
		};
};

class Map : public GameObject{
public:
	Map(SDL_Surface * working_surface, std::string atlas_location, bool debug);
	virtual ~Map();

	bool render();
	bool setUp();

	int size();

	Tile * getTile(int X, int Y);
	bool isBlockAvailableForConstruction(int mX, int mY, int sizeX, int sizeY, int decisionNumber);
	bool setBlockAvailableForConstruction(int mX, int mY, int sizeX, int sizeY, bool enable);

	void getSquareZeroPoint(int mX, int mY, int * newPosX, int * newPosY );
	void getCollunsAndRowsOfABloack(int sizeX, int sizeY, int * collum, int * row);

	int map_height, map_width, map_size, tile_width, tile_height, TilesetWidth ,TilesetHeight;
	bool debug;

private:

	Doodle * atlas;
	std::vector<Tile> tile_set;

	std::string atlas_location;
	std::string map_location;

	bool loadMapTxt();
	void debugRender();
	bool checkForEdgeOverFlow(int mX, int mY, int sizeX, int sizeY);


};

#endif /* MAP_H_ */
